﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CNFM_CROCODILE_LOGO.Services.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace CNFM_CROCODILE_LOGO_Web.Controllers
{
    /// <summary>
    /// 汇总分析
    /// </summary>
    public class SummaryReportController : Controller
    {
        private ISummaryReportServices _pro;

        public SummaryReportController(ISummaryReportServices pro)
        {
            this._pro = pro;
        }

        /// <summary>
        /// 地区分析
        /// </summary>
        /// <returns></returns>
        public IActionResult AreaList()
        {
            return View();
        }

        /// <summary>
        /// 产品分析
        /// </summary>
        /// <returns></returns>
        public IActionResult SpeciesManageList()
        {
            return View();
        }

        /// <summary>
        /// 企业分析
        /// </summary>
        /// <returns></returns>
        public IActionResult EnterpriseList()
        {
            return View();
        }

        /// <summary>
        /// 标签分析
        /// </summary>
        /// <returns></returns>
        public IActionResult ApplicationList()
        {
            return View();
        }

        /// <summary>
        /// 地区分析报表
        /// </summary>
        /// <param name="areaCode"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        [Authorize("Permission")]
        public JsonResult GetAreaReport(string unCode, string date, string enterpriseId, int type = 1)
        {
            var startDate = string.Empty;
            var endDate = string.Empty;

            if (!string.IsNullOrEmpty(date) && date != "null" && date != "undefined")
            {
                string[] arr = date.Split('~');
                startDate = arr[0];
                endDate = arr[1];
            }
            var ret = _pro.GetAreaReport(unCode, startDate, endDate, enterpriseId, type);
            return Json(ret);
        }

        /// <summary>
        /// 产品配发类型分析
        /// </summary>
        /// <param name="unCode"></param>
        /// <param name="smType"></param>
        /// <param name="date"></param>
        /// <param name="enterpriseId"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        [Authorize("Permission")]
        public JsonResult GetSpeciesManageTypeReport(string unCode, string smType, string date, string enterpriseId, int type = 1)
        {
            var startDate = string.Empty;
            var endDate = string.Empty;

            if (!string.IsNullOrEmpty(date) && date != "null" && date != "undefined")
            {
                string[] arr = date.Split('~');
                startDate = arr[0];
                endDate = arr[1];
            }
            var ret = _pro.GetSpeciesManageTypeReport(unCode, smType, startDate, endDate, enterpriseId, type);
            return Json(ret);
        }
        /// <summary>
        /// 企业分析报表
        /// </summary>
        /// <param name="unCode"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        [Authorize("Permission")]
        public JsonResult GetEnterpriseReport(string unCode, string date, string enterpriseId, int type = 1)
        {
            var startDate = string.Empty;
            var endDate = string.Empty;

            if (!string.IsNullOrEmpty(date) && date != "null" && date != "undefined")
            {
                string[] arr = date.Split('~');
                startDate = arr[0];
                endDate = arr[1];
            }

            var ret = _pro.GetEnterpriseReport(unCode, startDate, endDate, enterpriseId, type);
            return Json(ret);
        }

        /// <summary>
        /// 标签报表
        /// </summary>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        [Authorize("Permission")]
        public JsonResult GetApplicationReport(string unCode, string enterpriseId)
        {
            var ret = _pro.GetApplicationReport(unCode, enterpriseId);
            return Json(ret);
        }
    }
}